package com.example.learn_gl_android.anglib.core.gl

import android.opengl.GLES30
import android.opengl.GLSurfaceView

import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class DefaultGLIRenderer : GLSurfaceView.Renderer, IRendererAdapter {
    private var mOnInitHook : ArrayList<OnInit> = ArrayList()
    private var mOnScreenSizeChangedHook : ArrayList<OnScreenSizeChanged> = ArrayList()
    private var mOnDrawFrameHook : ArrayList<OnDrawFrame> = ArrayList()

    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
        mOnInitHook.forEach { it.act() }
    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
        GLES30.glViewport(0,0,width, height)

        mOnScreenSizeChangedHook.forEach { it.accept(width,height) }
    }

    override fun onDrawFrame(gl: GL10?) {
        mOnDrawFrameHook.forEach { it.act() }
    }

    override fun addToOnInitHook(callback: OnInit) {
        mOnInitHook.add(callback)
    }

    override fun addToOnScreenSizeChangedHook(callback: OnScreenSizeChanged) {
        mOnScreenSizeChangedHook.add(callback)
    }

    override fun addToOnDrawFrameHook(callback: OnDrawFrame) {
        mOnDrawFrameHook.add(callback)
    }


}